class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals)
    {
        sort(intervals.begin(), intervals.end());
        int left = intervals[0][0], right = intervals[0][1];
        vector<vector<int>> ret;
        for (int i = 0; i < intervals.size(); i++)
        {
            int a = intervals[i][0], b = intervals[i][1];
            if (a <= right)
            {
                right = max(b, right);
            }
            else
            {
                ret.push_back({ left,right });
                left = a;
                right = b;
            }
        }
        ret.push_back({ left,right });
        return ret;
    }
};